package fit.acmetelecom;

import static com.acmetelecom.call.CallEventBuilder.aCallFrom;
import static com.acmetelecom.call.CallEventBuilder.asDateTime;

import org.joda.time.DateTime;

import com.acmetelecom.customer.Customer;

import fit.ColumnFixture;

public class LogEndedCalls extends ColumnFixture {
	public String   FromName;
	public String   FromNumber;
	public String   ToName;
	public String   ToNumber;
	public DateTime Ended;

	@Override
	public void reset() throws Exception {
		FromName   = null;
		FromNumber = null;
		ToName     = null;
		ToNumber   = null;
		Ended      = null;
		super.reset();
	}
	
	@Override
	public void execute() throws Exception {
		Customer srcCust  = AcmeTelecomFitSystem.getCustomer(FromName, FromNumber);
		Customer destCust = AcmeTelecomFitSystem.getCustomer(ToName, ToNumber);
		
		AcmeTelecomFitSystem.systemUnderTest.log(aCallFrom(srcCust).to(destCust).endedAt(Ended));
		super.execute();
	}
	
	@Override
	public Object parse(String s, Class<?> type) throws Exception {
		if(type == DateTime.class) {
			return asDateTime(s);
		}
		return super.parse(s, type);
	}
}
